package com.flyoil.petromp.ui.activity.activity_notice;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.cnpc.fyimageloader.glide.GlideHelper;
import com.cnpc.fyutils.ToastUtils;
import com.cnpc.fyviewlibrary.view.CircleImageView;
import com.cnpc.fyviewlibrary.view.CircleTextView;
import com.flyoil.petromp.Constant.ConstantNetworkCode;
import com.flyoil.petromp.R;
import com.flyoil.petromp.apiservice.HttpModel;
import com.flyoil.petromp.apiservice.OnObserverRetrofitResetCallBack;
import com.flyoil.petromp.base.BaseActivity;
import com.flyoil.petromp.base.BaseEntity;
import com.flyoil.petromp.entity.entity_notice.NoticeMessageEntity;

import java.util.HashMap;
import java.util.Map;

/**
 * 公告的详情界面
 */
public class NoticeMessageActivity extends BaseActivity {
    private TextView tv_name, tv_time, tv_title, tv_content;
    private CircleImageView img_head;

    @Override
    protected int getContentViewResId() {
        return R.layout.activity_notice_message;
    }

    @Override
    protected void initViews() {
        super.initViews();
        setTextTitleName("公告详情");
        setBackOnclickListner(mContext);
        tv_name = $(R.id.tv_notice_message_name);
        tv_time = $(R.id.tv_notice_message_time);
        tv_title = $(R.id.tv_notice_message_title);
        tv_content = $(R.id.tv_notice_message_content);
        img_head = $(R.id.img_notice_message_head);
        httpModel = new HttpModel();
    }

    @Override
    protected void initdatas() {
        super.initdatas();
        Map<String, Object> map = new HashMap<>();
        map.put("id", getIntent().getIntExtra("id", 0));
        httpModel.getNoticeMessage(map, new OnObserverRetrofitResetCallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity model) {
                super.onSuccess(model);
                NoticeMessageEntity entity = null;
                if (model instanceof BaseEntity) {
                    entity = (NoticeMessageEntity) model;
                }
                if (entity != null && entity.getData() != null && model.getCode() == ConstantNetworkCode.SuccedCode) {
                    onDataSucceed();
                    tv_name.setText(entity.getData().getUsername());
                    tv_time.setText(entity.getData().getCreatedTimeLabel());
                    tv_title.setText(entity.getData().getTitle());
                    tv_content.setText("\u3000\u3000" + entity.getData().getContent());
                    GlideHelper.showImage(mContext, entity.getData().getUrl(), img_head, R.mipmap.user_head_icon);

                } else {
                    onDataNull(null);
                    ToastUtils.show_toast(model.getMessage());
                }
            }

            @Override
            public void onFailure(String msg) {
                onDataError(null);
            }
        });
    }
}
